<admintpl file="header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<if condition="(I('get.disp') eq 'm1')">
				<li><a href="{:U('Examine/loan_overdue_m1')}">逾期M1列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id'],'disp'=>'m1'))}">{$order.name}详情</a></li>
			<elseif condition="(I('get.disp') eq 'm2')"/>
				<li><a href="{:U('Examine/loan_overdue_m2')}">逾期M2列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id'],'disp'=>'m2'))}">{$order.name}详情</a></li>	
			<else />
				<li><a href="{:U('Examine/loan_overdue')}">逾期列表</a></li>
				<li ><a href="{:U('Examine/overdue_info',array('id'=>$order['id']))}">{$order.name}详情</a></li>
			</if>
			<li class="active"><a>逾期续期审核</a></li>
			
		</ul>
        <form class="form-horizontal js-ajax-form" method="post">
			<fieldset>
				<div class="tabbable">
					<div class="tab-content">
						
							<fieldset>
								<div class="control-group">
									<label class="control-label">姓名</label>
									<div class="controls">
										<php>$ds=array('0'=>'<span style="color:red">未认证</span>','1'=>'<span style="color:green">已认证</span>','2'=>'<span style="color:red">认证未通过</span>','3'=>'<span style="color:red">暂时不需要</span>')</php>
										<label class="control-label" style="width:auto">{$order.name}&nbsp&nbsp&nbsp&nbsp{$ds[$order['account_status']]}</label>
										<input type="hidden" name="options[id]" value="{$order.id}">
										<input type="hidden" name="options[user_id]" value="{$order.user_id}">
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">手机号码</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.mobile}</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">银行卡号</label>
									<div class="controls">
									<label class="control-label" style="width:auto">{$order.bank}：{$order.silver_card}&nbsp&nbsp&nbsp&nbsp预留手机号码&nbsp&nbsp{$order.silver_number}</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">借款金额</label>
									<div class="controls">
									<label class="control-label" style="width:auto">{$order.amount}元</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">借款天数</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.loan_day}天</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">放款日</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.loan_time}</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">分期数</label>
									<div class="controls">
										<label class="control-label" style="width:auto">{$order.stages}期</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">咨询费</label>
									<div class="controls">
									<label class="control-label" style="width:auto">{$order.interest}元</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">审核费</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.examine}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">顾问费</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.consulting}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">到期应还</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.loan_amount}元</label></div>
								</div>
								<br />
								<div class="control-group">
									<label class="control-label">分期详情</label>
									<div class="controls">
									<label class="control-label" style="width:auto">
										<!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
										<table class="table table-bordered">
											<tr>
												<th>期数</th>
												<th>到期时间</th>
												<th>借款状态</th>
												<th>分期金额</th>
												<th>审核操作</th>
											</tr>
											<php>$li=0;$stu_type=array('1'=>'借款中','2'=>'已还款','3'=>'逾期','4'=>'已到期','5'=>'审核中','6'=>'审核不通过','7'=>'驳回','8'=>'放款成功','9'=>'放款不成功','10'=>'待放款')</php>
											<php>$sub_count = count($sub);</php>
											<foreach name="sub" item="vo">
												<tr>
													<td>
														<eq name="sub_count" value="1">
															第1期
															<else/>
															第{:substr((string)$vo['stages'],0,1)}期
														</eq>
													</td>
													<td>{$vo.endtime}</td>
													<td>{$stu_type[$vo['status']]}</td>
													<td>{$vo.amount}</td>
													<td>
													<if condition="$vo['status'] eq 3">
														<if condition="empty($li)">
															<span>
																<!--判断是不是最小的逾期订单ID-->
															<if condition="$min_yu_id == $vo['id']">
																<input name="options[status]" type="radio" checked="checked" value="{$vo.id}" />
																<else/>
																<input name="options[status]" type="radio" value="{$vo.id}" disabled class="disabled" />
															</if>
															借款中</span>


														<else/>
														
														</if>
													<else/>
													</if>
													</td>
												</tr>
											</foreach>
												<tr>
													<td>共{$order.stages}期</td>
													<td>{$order.loan_day}天</td>
													<td>{$stu_type[$order['status']]}</td>
													<td>{$order.amount}</td>
													<td></td>
												</tr>
										</table>
									</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">续期详情</label>
									<div class="controls">
									<label class="control-label" style="width:auto">
									<if condition="(empty($renewal))">
										暂无记录
									<else/>
										<!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
										<table class="table table-bordered">
											<tr>
												<th>借款编号</th>
												<th>续期时间</th>
												<th>完结时间</th>
												<th>续期金额</th>
												<th>审核备注</th>
												<th>状态</th>
												<th>审核人</th>
											</tr>
											<foreach name="renewal" item="vo">
												<tr>
													<td>{$vo.order_id}</td>
													<td>{$vo.renewal}</td>
													<td>{$vo.endtime}</td>
													<td>{$vo.amount}</td>
													<td>{$vo.message}</td>
													<td>{$vo['status']==1?'审核成功':'审核失败'}</td>
													<td>{$lastuser[$vo['lastuser_id']]|default='系统'}</td>
												</tr>
											</foreach>
										</table>
									</if>
									</label>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">审核记录</label>
									<div class="controls">
									<label class="control-label" style="width:auto">
									<if condition="(empty($logs))">
										暂无记录
									<else/>
										<!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
										<table class="table table-bordered">
											<tr>
												<th>审核类型</th>
												<th>审核时间</th>
												<th>审核备注</th>
												<th>金额</th>
												<th>实收金额<br/>(不含逾期费)</th>
												<th>实收逾期费</th>
												<th>微信实收</th>
												<th>支付宝实收</th>
												<th>银行实收</th>
												<th>审核操作</th>
												<th>审核人</th>
												<th>收款人</th>
											</tr>
											<php>$stu_type=array('1'=>'借款中','2'=>'已还款','3'=>'逾期','4'=>'已到期','5'=>'审核中','6'=>'审核不通过','7'=>'驳回','8'=>'放款成功','9'=>'放款不成功','10'=>'待放款');
											$stu_ty=array('0'=>'用户审核','1'=>'订单审核','2'=>'订单审核','3'=>'续期审核','4'=>'逾期还款(本金)','5'=>'逾期还款','6'=>'订单审核','7'=>'客户还款');
											</php>
											<foreach name="logs" item="vo">
												<tr>
													<td>{$stu_ty[$vo['types']]}</td>
													<td>{$vo.crtime}</td>
													<td>{$vo.message}</td>
													<td>{$vo.amount}</td>
													<td>{$vo.real_amount|default='0.00'}</td>
													<td>{$vo.overdue_amount|default='0.00'}</td>
													<td>{$vo.wechat_amount}</td>
													<td>{$vo.alipay_amount}</td>
													<td>{$vo.bank_amount}</td>
													<td>{$vo['status']?'审核成功':'审核失败'}</td>
													<td>{$lastuser[$vo['examine_id']]|default='系统'}</td>
													<td>{$lastuser[$vo['payee']]}</td>
												</tr>
											</foreach>
										</table>
									</if>
									</label>
									</div>
								</div>
								<php>$overdue=check_amount_user_overdue($order['user_id']);</php>
								<div class="control-group">
									<label class="control-label">逾期天数</label>
									<div class="controls"><label class="control-label" style="width:auto">{$overdue.over_day|default='0'}天</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">逾期金额</label>
									<php>$over_amount=yu_amount($order['user_id']);</php>
									<div class="controls"><label class="control-label" style="width:auto">{$over_amount|default='0'}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">还款时间</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.endtime}</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">账号余额</label>
									<div class="controls"><label class="control-label" style="width:auto">{$order.deposit|default=0}元</label></div>
								</div>
								<div class="control-group">
									<label class="control-label">实收逾期费</label>
									<div class="controls">
										<input type="text" name="options[overdue_amount]" class="just_can_number" size="11"  placeholder="请输入数字" /><span style="color: #b4b4b4">&nbsp;备注：请输入收到的逾期费(没有则不用填或填0)，小心忘记了</span>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">
										<b style="color:red;">* </b><strong>收款方式</strong>
									</label>
									<div class="controls">
										<select id="pay_ways">
											<!--<option value="0">请选择一种收款方式</option>-->
											<option value="1">微信</option>
											<option value="2">支付宝</option>
											<option value="3">银行</option>
										</select>
										<button id="pay_add" type="button" class="btn btn-success">添加</button>
										<button  id="pay_del" style="display: none;" type="button" class="btn btn-danger">减少</button>
									</div>
									<script>
                                        $(function(){
                                            var wechat_amount = $("#wechat_amount");
                                            var alipay_amount = $("#alipay_amount");
                                            var bank_amount = $("#bank_amount");
                                            //增加
                                            $('#pay_add').click(function(){
                                                var storges = [1,2,3];
                                                for (var i in storges) {
                                                    var obj = $('.pay_'+storges[i]);
                                                    var dis = obj.css('display');
                                                    if(dis === 'none'){
                                                        obj.show();
                                                        break;
                                                    }
                                                }
                                                var pay_1 = $('.pay_'+storges[0]);
                                                var pay_2 = $('.pay_'+storges[1]);
                                                var pay_3 = $('.pay_'+storges[2]);
                                                var dis_1 = pay_1.css('display');
                                                var dis_2 = pay_2.css('display');
                                                var dis_3 = pay_3.css('display');
                                                var flag1 = (dis_1 === 'block' && dis_2 === 'block' && dis_3 === 'block');
                                                var flag2 = (dis_1 === 'none' && dis_2 === 'none' && dis_3 === 'none');
                                                var pay_del = $('#pay_del');
                                                if(true === flag1){
                                                    $(this).hide();
                                                    pay_del.show();
                                                }else if(false === flag1 && false === flag2){
                                                    $(this).show();
                                                    pay_del.show();
                                                }else if(false === flag1 && true === flag2){
                                                    $(this).show();
                                                    pay_del.hide();
                                                }
                                            });
                                            //减少
                                            $('#pay_del').click(function(){
                                                var storges = [3,2,1];
                                                for (var i in storges) {
                                                    var obj = $('.pay_'+storges[i]);
                                                    var dis = obj.css('display');
                                                    if(dis === 'block'){
                                                        obj.hide();
                                                        obj.find('input').val('');//凡是隐藏了的，必须值也清空
                                                        break;
                                                    }
                                                }
                                                var pay_3 = $('.pay_'+storges[0]);
                                                var pay_2 = $('.pay_'+storges[1]);
                                                var pay_1 = $('.pay_'+storges[2]);
                                                var dis_1 = pay_1.css('display');
                                                var dis_2 = pay_2.css('display');
                                                var dis_3 = pay_3.css('display');
                                                var flag1 = (dis_1 === 'block' && dis_2 === 'block' && dis_3 === 'block');
                                                var flag2 = (dis_1 === 'none' && dis_2 === 'none' && dis_3 === 'none');
                                                var pay_add = $('#pay_add');
                                                if(true === flag1){
                                                    $(this).show();
                                                    pay_add.hide();
                                                }else if(false === flag1 && false === flag2){
                                                    var flag3 = (dis_1 === 'block' && dis_2 === 'none' && dis_3 === 'none');
                                                    if(flag3){
                                                        $(this).hide();
                                                        pay_add.show();
                                                    }else{
                                                        $(this).show();
                                                        pay_add.show();
                                                    }
                                                }else if(false === flag1 && true === flag2){
                                                    $(this).hide();
                                                    pay_add.show();
                                                }

                                            });
                                            //下拉
                                            $('#pay_ways').change(function(){
                                                $('#pay_add').show();
                                                $('#pay_del').hide();
                                                if(0 !== parseInt($(this).val())){
                                                    switch(parseInt($(this).val())){
                                                        case 1:
                                                            wechat_amount.show();
                                                            alipay_amount.hide();
                                                            bank_amount.hide();
                                                            alipay_amount.find('input').val('');
                                                            bank_amount.find('input').val('');
                                                            break;
                                                        case 2:
                                                            wechat_amount.hide();
                                                            alipay_amount.show();
                                                            bank_amount.hide();
                                                            wechat_amount.find('input').val('');
                                                            bank_amount.find('input').val('');
                                                            break;
                                                        case 3:
                                                            wechat_amount.hide();
                                                            alipay_amount.hide();
                                                            wechat_amount.find('input').val('');
                                                            alipay_amount.find('input').val('');
                                                            bank_amount.show();
                                                            break;
                                                    }
                                                }else{
                                                    wechat_amount.hide();
                                                    alipay_amount.hide();
                                                    bank_amount.hide();
                                                }
                                            });
                                        });
									</script>
								</div>
								<div class="control-group pay_1" id="wechat_amount" style="display: block;">
									<label class="control-label">微信实收</label>
									<div class="controls">
										<input type="text" name="options[wechat_amount]" class="just_can_number" size="11"  placeholder="请输入数字" />
									</div>
								</div>
								<div class="control-group pay_2" id="alipay_amount" style="display: none;">
									<label class="control-label">支付宝实收</label>
									<div class="controls">
										<input type="text" name="options[alipay_amount]" class="just_can_number" size="11" placeholder="请输入数字" />
									</div>
								</div>
								<div class="control-group pay_3" id="bank_amount" style="display: none;">
									<label class="control-label">银行实收</label>
									<div class="controls">
										<input type="text" name="options[bank_amount]" class="just_can_number" size="11" placeholder="请输入数字" />
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">选择收款人员</label>
									<div class="controls">
										<select name="options[payee]">
											<option value="{:get_current_admin_id()}">自己</option>
											<foreach name="daihou" item="vo">
												<option value="{$vo.id}">{$vo.user_login}</option>
											</foreach>
										</select>
									</div>
								</div>

								<!--判断是否有逾期记录，如果有，可以选否，并且可以显示出来-->
								<if condition="$yu_amount['list']">
									<div class="control-group">
										<label class="control-label">是否要收逾期费</label>
										<div class="controls">
											<select name="options[is_pay_yu]">
												<option value="1">是</option>
												<option value="0">否</option>
											</select>
											<span style="color: #b4b4b4">&nbsp;备注：未及时操作用户续期申请情况时（如：用户23:59:59申请了续期，但是工作人员未审核该续期申请）</span>
										</div>
									</div>
									<script>
										$('select[name="options[is_pay_yu]"]').change(function(){
										    if(parseInt($(this).val()) === 0){
										        $('#cancel_yu_block').show();
											}else{
										        $('#cancel_yu_block').hide();
											}
										});
									</script>
									<div class="control-group" id="cancel_yu_block" style="display: none;">
										<label class="control-label">请选择要取消逾期费的分期</label>
										<div class="controls">
											<table class="table table-bordered">
												<tr>
													<th>选择</th>
													<th>分期数</th>
													<th>逾期金额</th>
												</tr>
												<php>
													foreach($yu_amount['list'] as $stages=>$amount):
												</php>
												<tr>
													<td><input class="cancel_yu" type="checkbox" name="options[cancel_yu][{$stages}]" value="{$stages}" onclick="cancel_yu(this,'{$amount}');" /></td>
													<td>
														第
														<php>
															if($order['stages']==1):
																echo 1;
															else:
																echo substr($stages,0,1);
															endif;
														</php>
														期
													</td>
													<td>{$amount}</td>
												</tr>
												<php>
													endforeach;
												</php>
											</table>
										</div>
										<div class="control-group">
											<label class="control-label">用户转账时间是几天前</label>
											<div class="controls">
												<input type="text" class="just_can_number" name="options[late_yu_days]" value="1" placeholder="请输入数字" /><span style="color: #b4b4b4">&nbsp;备注：默认1，表示用户昨天还款，工作人员今天才给这个用户做续期操作</span>
											</div>
										</div>
									</div>
									<script>
										function cancel_yu(obj,amount){
//										    alert($(obj).prop('checked'));
//											alert(amount);
											var amt_obj = $('#amount');
											if($(obj).prop('checked')===true){
                                                amt_obj.text((parseInt(amt_obj.text())-parseInt(amount))+'元');
											}else{
                                                amt_obj.text((parseInt(amt_obj.text())+parseInt(amount))+'元');
											}
										}
									</script>
								</if>

								<div class="control-group">
									<label class="control-label">审核备注</label>
									<div class="controls">
										<textarea name="options[message]" rows="4" cols="30"></textarea>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label">续期调整</label>
									<div class="controls">
										<php>$am=xu_amount(array($order))</php>
										<input type="radio" name='options[orther_time]' onclick='ck(1)' checked="checked" value='1' style='margin: 0 0 0 30px;'/>1天
										<input type="radio" name='options[orther_time]' onclick='ck(2)' value='2' style='margin: 0 0 0 30px;'/>2天
										<input type="radio" name="options[orther_time]" onclick='ck(6)' value='6' style='margin: 0 0 0 30px;'/>6天
										<input type="radio" name='options[orther_time]' onclick='ck(7)' value='7' style='margin: 0 0 0 30px;'/>7天
										<span style='margin: 0 0 0 30px;'>续期金额</span><b id='amount'>{$am['renewal_fee']+$over_amount}元</b>
									</div>
									<script>
										//点击选择续期的时候，要重置逾期减额
										$('input[name="options[orther_time]"]').click(function(){
										    $('.cancel_yu').prop('checked',false);
										});
									</script>
								</div>
							</fieldset>
					</div>
				</div>
				<div class="form-actions">
					<button class="btn btn-primary js-ajax-submit" type="submit" data-types='1' data-action="{:U('Examine/overdue_renwal_act')}" data-msg='确认续期?' data-subcheck="true">审核续期确认</button>
					<a class="btn btn-primary js-ajax-submit"  href="{:U('Examine/loan_expire')}" >返回</a>
				</div>
			</fieldset>
		</form>
		
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
</body>
<script type="text/javascript">
	var ajaxForm_list = $('form.js-ajax-form');
	if (ajaxForm_list.length) {
	    Wind.use('ajaxForm', 'artDialog', function () {
			
	        $('button.js-ajax-submit').bind('click', function (e) {

	            e.preventDefault();
	            /*var btn = $(this).find('button.js-ajax-submit'),
						form = $(this);*/
	            var btn = $(this),
	                form = btn.parents('form.js-ajax-form');
	
	            //批量操作 判断选项
	            if (btn.data('subcheck')) {
	                btn.parent().find('span').remove();
					var msg = btn.data('msg');
					if (msg) {
						art.dialog({
							id: 'warning',
							icon: 'warning',
							content: btn.data('msg'),
							cancelVal: "{:L('CLOSE')}",
							cancel: function () {
								
							},
							button :[ {
											name : "{:L('OK')}",
											callback:function(){
												ajaxSubmit(btn.data('types'));
											},
											focus : true
									} ]
						});
					} else {
						btn.data('subcheck', false);
						btn.click();
					}
	                return false;
	            }
	        });
	
	    });
	}
	function ajaxSubmit(type){
			var btn = $('button.js-ajax-submit'),
			form = btn.parents('form.js-ajax-form');
			form.ajaxSubmit({
	                url: type ? btn.data('action') : form.attr('action'),
	                //按钮上是否自定义提交地址(多按钮情况)
	                dataType: 'json',
	                beforeSubmit: function (arr, $form, options) {
						var tx=type ? '审核通过' : '审核不通过';
	                    //按钮文案、状态修改
	                    btn.text(tx + '中...').attr('disabled', true).addClass('disabled');
	                },
	                success: function (data, statusText, xhr, $form) {
	                    //按钮文案、状态修改
	                    btn.removeClass('disabled').parent().find('span').remove();
	
	                    if (data.state === 'success') {
	                        $('<span class="tips_success">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('slow').delay(1000).fadeOut(function () {
	                            if (data.referer) {
	                                //返回带跳转地址
	                                if (window.parent.art) {
	                                    //iframe弹出页
	                                    window.parent.location.href = data.referer;
	                                } else {
	                                    window.location.href = data.referer;
	                                }
	                            } else {
	                                if (window.parent.art) {
	                                    reloadPage(window.parent);
	                                } else {
	                                    //刷新当前页
	                                    reloadPage(window);
	                                }
	                            }
	                        });
	                    } else if (data.state === 'fail') {
	                        $('<span class="tips_error">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('fast');

	                        btn.text('手工确认还款调整').removeProp('disabled').removeClass('disabled');
	                    }
	                }
	            });
	}
	function ck(id){
		//var id=$("#days option:selected").val();
		//var stages=$('input:radio[name="stages"]:checked').val();
		switch (id){
			case 1:
				document.getElementById('amount').innerHTML='{$am["renewal_fee"]+$over_amount}元';
				break;
			case 2:
				document.getElementById('amount').innerHTML='{$am["renewal_fee"]*2+$over_amount}元';
				break;
			case 6:
                document.getElementById('amount').innerHTML='{$am["renewal_fee_sev"]+$over_amount}元（说明：6天续期金额和7天续期金额一样）';
                break;
			case 7:
				document.getElementById('amount').innerHTML='{$am["renewal_fee_sev"]+$over_amount}元';
				break;
		}
	}
	</script>
<script>
    $(function(){
        $('.just_can_number').keyup(function(){
            var obj = this;
            obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
            obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        });
    });
</script>
</html>